package com.web.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

import java.util.Calendar;

/**
 *
 * @author xukk
 * @date 2017/5/31
 */
@Slf4j
@Component
public class ApplicationStartup implements ApplicationListener<ContextRefreshedEvent> {
    @Autowired
    private RedisTemplate<String, String> redisTemplate;
    @Override
    public void onApplicationEvent(ContextRefreshedEvent event) {
        try {
            redisTemplate.boundValueOps("now_time").set(String.valueOf(Calendar.getInstance().getTimeInMillis()));
        } catch (Exception e) {
            log.warn("redis 初始化失败 =======================================");
        }

    }
}